// miniprogram/pages/cloudDB.js
Page({

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const db = wx.cloud.database()
    console.log("数据库初始化操作完成---页面加载时触发");
    console.log(db);
    const cloudDB = db.collection('cloudDB');
    console.log("指定数据库表操作完成---页面加载时触发");
    console.log(cloudDB);
    db.collection('cloudDB').get().then(res=>{
      console.log(res);
    })
    
  },
  /**
   * 对云数据库的增删改车操作
   */
  demo_find(){
    const db = wx.cloud.database();
    db.collection('cloudDB').get().then(res=>{
      console.log(res);
    })
  },
  demo_add(){
    const db = wx.cloud.database();
    db.collection('cloudDB').add({
      data: {
        username : "李四",
        age: 33
      }
    }).then(res=>{
      console.log(res);
    })
  },
  demo_update(){
      const db = wx.cloud.database();
      db.collection('cloudDB').doc('b45a21d55fe018f70006d19771506090').update({
        data:{
          age: 17,
        }
      }).then(res=>{
        console.log(res);
      })
  },
  demo_delete(){
    wx.cloud.database().collection('cloudDB').doc('b45a21d55fe018f70006d19771506090').remove().then(res=>{
      console.log(res);
    })
  },
})